/*    */ package com.zimbra.cs.service.mail;
/*    */ 
/*    */ import com.zimbra.common.account.Key.DataSourceBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.MailConstants;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.DataSource;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.datasource.DataSourceManager;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class ImportData
/*    */   extends MailDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 39 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 40 */     Provisioning prov = Provisioning.getInstance();
/* 41 */     Account account = getRequestedAccount(zsc);
/*    */     
/* 43 */     for (Element elem : request.listElements())
/*    */     {
/*    */ 
/* 46 */       String id = elem.getAttribute("id", null);
/* 47 */       if (id != null) {
/* 48 */         DataSource ds = prov.get(account, Key.DataSourceBy.id, id);
/* 49 */         if (ds == null)
/* 50 */           throw ServiceException.INVALID_REQUEST("Could not find Data Source with id " + id, null);
/*    */       } else { String name;
/* 52 */         if ((name = elem.getAttribute("name", null)) != null) {
/* 53 */           DataSource ds = prov.get(account, Key.DataSourceBy.name, name);
/* 54 */           if (ds == null) {
/* 55 */             throw ServiceException.INVALID_REQUEST("Could not find Data Source with name " + name, null);
/*    */           }
/*    */         } else {
/* 58 */           throw ServiceException.INVALID_REQUEST("must specify either 'id' or 'name'", null);
/*    */         } }
/*    */       DataSource ds;
/* 61 */       ZimbraLog.addDataSourceNameToContext(ds.getName());
/* 62 */       DataSourceManager.asyncImportData(ds);
/*    */     }
/*    */     
/* 65 */     Element response = zsc.createElement(MailConstants.IMPORT_DATA_RESPONSE);
/* 66 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/ImportData.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */